<template>
    <div id="header">
        <el-button type="primary" @click="dialogVisible1()">新增婚纱</el-button>
    </div>

    <!-- 对话框 -->
    <el-dialog v-model="dialogVisible" title="Tips" width="500" draggable>
        <el-form :model="form" label-width="auto" style="max-width: 600px">
            <el-form-item label="合集名称">
                <el-input v-model="form.name" />
            </el-form-item>
            <el-form-item label="类别">
                <el-cascader v-model="form.type" :options="options" @change="handleChange"
                    :props="{ value: 'name', label: 'name', children: 'children' }" />
            </el-form-item>

            <el-form-item label="介绍">
                <el-input v-model="form.desc" type="textarea" />
            </el-form-item>

        </el-form>
        <template #footer>
            <div class="dialog-footer">
                <el-button @click="dialogVisible = false">Cancel</el-button>
                <el-button type="primary" @click="hunshaadd()">
                    添加
                </el-button>
            </div>
        </template>
    </el-dialog>
    <!-- 表格 -->
    <div>

        <el-table :data="tableData" style="width: 100%">
            <el-table-column prop="name" label="Name" width="180">
                <template #default="scope">{{ scope.row.name }}</template>
            </el-table-column>
            <el-table-column prop="desc" label="desc" width="180" />
            <el-table-column prop="type" label="类别" width="180" />
            <el-table-column prop="address" label="Address">
                <template #default="scope">
                    <el-button type="text" @click="hunshaaddzp(scope.row._id, scope.row.name)">添加照片</el-button>
                </template>

            </el-table-column>
        </el-table>
    </div>
</template>
<script lang="ts" setup>
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import { useRouter } from 'vue-router';
const router = useRouter()
const dialogVisible = ref(false)
const dialogOverflowVisible = ref(false)
let dialogVisible1 = () => {
    dialogVisible.value = !dialogVisible.value;

};
// 表单元素
const form = reactive({
    name: '',
    type: [],
    desc: '',
})
const options = reactive([])
const handleChange = (value: any) => {
    console.log(value)
}
onMounted(() => {
    getType()
    hunshalist()
})
let getType = async () => {
    let { data } = await axios.get('http://localhost:3000/web/gethunshatype')
    console.log(data);
    Object.assign(options, data.data)

}


// t添加婚纱
let hunshaadd = async () => {
    console.log(form);

    let { data } = await axios.post('http://localhost:3000/web/addhunshaitem', form)
    console.log(data);
    if (data.code == 200) {
        dialogVisible.value = !dialogVisible.value;
        form.name = ''
        form.type = []
        form.desc = ''
        hunshalist()
    } else {
        alert('添加失败')
    }
}
// 表格
let tableData = reactive([])
// 查看婚纱
let hunshalist = async () => {
    let { data } = await axios.get('http://localhost:3000/web/gethunshaitem')
    console.log(data);
    if (data.code == 200) {
        Object.assign(tableData, data.data)
    }
}
// 添加婚纱照片
let hunshaaddzp = (id: any, name: any) => {
    router.push({ path: '/large', query: { _id: id, name: name } })
}
</script>
<style scoped>
#header {
    width: 100%;
    height: 10vh;
    background-color: #f1cece
}
</style>